package cn.afterturn.easypoi.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * 文件上传后,返回文件的路径信息
 */
@RestController
@RequestMapping("/excel")
public class importExcelController {



    @PostMapping("/import")
    public String importExcel(@RequestParam("excelFile") MultipartFile excelFile, HttpServletRequest request) throws Exception {

        String storePath = request.getSession().getServletContext().getRealPath("/") + "upload/";
        excelFile.transferTo(new File(storePath + excelFile.getOriginalFilename()));
        return storePath+excelFile.getOriginalFilename();
    }

}
